﻿// Shader-Based-Image-Processing (SBIP)
// http://code.google.com/p/sbip/
//
// Copyright © Frank Nagl, 2009-2010
// admin@franknagl.de
//
using System;
using System.Collections.Generic;
using SBIP.Controls;
using SBIP.Filter.NonSBIP;
using SBIP.Helper;
using SBIP.Helper.ColorSpace;

namespace TestSBIP
{
    using System.Drawing;
    using System.Drawing.Imaging;
    using SBIP;
    using SBIP.Filter;
    using System.Windows.Forms;
    using System.Threading;

    class Program
    {
        static void Main()
        {
            string s = StringBuilder.Substring("Frank ist sau cool...", 'F', 'o', false);
            string s2 = StringBuilder.Substring("Frank ist sauxyz cool...", "Fra", "xyz");
            string s3 = StringBuilder.Substring(
                "Frank ist sauxyz echt nen super saugeil cooler Typ...", "Fra", "er", false);
            Console.WriteLine(s);
            Console.WriteLine(s2);
            Console.WriteLine(s3);

            string file;
            string[] dirs;
            StringBuilder.SplitPathInFileAndDirectories(
                @"C:\Users\Frank\Desktop\IPCV2011-Las-Vegas\Foto vom tollen frank.jpg", out file, out dirs);
            Console.WriteLine(file);
            Console.WriteLine(dirs.ToString());
            MessageBox.Show(s2);
            return;

            Application.EnableVisualStyles();

            Bitmap bitmap2 = new Bitmap(@"C:\Paper\Paper3DOR2012-3D-Figures\fig\results\diagonal\Wireframe.png");
            NSWireframer filter2 = new NSWireframer();
            bitmap2 = filter2.Apply(bitmap2);
            bitmap2.Save(@"C:\Paper\Paper3DOR2012-3D-Figures\fig\results\diagonal\Wireframe-invert.png");
            return;
            //#region GET COLOR SPACE RANGES
            ////Bitmap bitmap = new Bitmap("all16777216rgb.png");
            ////NSColorSpaceRangeDetector colorSpaceRangeDetector = new NSColorSpaceRangeDetector();
            ////bitmap = colorSpaceRangeDetector.Apply(bitmap);
            ////colorSpaceRangeDetector.SaveListsInFile("All-Ranges.csv");
            //#endregion GET COLOR SPACE RANGES

            //#region GET BERND-INDEX52 COLOR TRIPLE IMAGES OF ALL COLOR SPACES
            //Bitmap bitmap = new Bitmap("Bernd-Index52.jpg");
            //NSSplitColorSpaceChannels filter = new NSSplitColorSpaceChannels();

            ////HSB
            //Console.WriteLine("HSB");
            //filter.ColorSpace = ColorSpaceEnum.HSB;
            //filter.ColorTriple = ColorTripleEnum.A;
            //bitmap = filter.Apply(bitmap);
            //SBIP.Helper.ImageConverter.SetColorPaletteToGray(bitmap);
            //bitmap.Save("ColorSpaceTest/HSB-Channel-A.png", ImageFormat.Png);
            //bitmap = new Bitmap("Bernd-Index52.jpg");
            //filter.ColorTriple = ColorTripleEnum.B;
            //bitmap = filter.Apply(bitmap);
            //SBIP.Helper.ImageConverter.SetColorPaletteToGray(bitmap);
            //bitmap.Save("ColorSpaceTest/HSB-Channel-B.png", ImageFormat.Png);
            //bitmap = new Bitmap("Bernd-Index52.jpg");
            //filter.ColorTriple = ColorTripleEnum.C;
            //bitmap = filter.Apply(bitmap);
            //SBIP.Helper.ImageConverter.SetColorPaletteToGray(bitmap);
            //bitmap.Save("ColorSpaceTest/HSB-Channel-C.png", ImageFormat.Png);

            ////HSL
            //Console.WriteLine("HSL");
            //filter.ColorSpace = ColorSpaceEnum.HSL;
            //bitmap = new Bitmap("Bernd-Index52.jpg");
            //filter.ColorTriple = ColorTripleEnum.A;
            //bitmap = filter.Apply(bitmap);
            //SBIP.Helper.ImageConverter.SetColorPaletteToGray(bitmap);
            //bitmap.Save("ColorSpaceTest/HSL-Channel-A.png", ImageFormat.Png);
            //bitmap = new Bitmap("Bernd-Index52.jpg");
            //filter.ColorTriple = ColorTripleEnum.B;
            //bitmap = filter.Apply(bitmap);
            //SBIP.Helper.ImageConverter.SetColorPaletteToGray(bitmap);
            //bitmap.Save("ColorSpaceTest/HSL-Channel-B.png", ImageFormat.Png);
            //bitmap = new Bitmap("Bernd-Index52.jpg");
            //filter.ColorTriple = ColorTripleEnum.C;
            //bitmap = filter.Apply(bitmap);
            //SBIP.Helper.ImageConverter.SetColorPaletteToGray(bitmap);
            //bitmap.Save("ColorSpaceTest/HSL-Channel-C.png", ImageFormat.Png);

            ////LAB
            //Console.WriteLine("LAB");
            //filter.ColorSpace = ColorSpaceEnum.LAB;
            //bitmap = new Bitmap("Bernd-Index52.jpg");
            //filter.ColorTriple = ColorTripleEnum.A;
            //bitmap = filter.Apply(bitmap);
            //SBIP.Helper.ImageConverter.SetColorPaletteToGray(bitmap);
            //bitmap.Save("ColorSpaceTest/LAB-Channel-A.png", ImageFormat.Png);
            //bitmap = new Bitmap("Bernd-Index52.jpg");
            //filter.ColorTriple = ColorTripleEnum.B;
            //bitmap = filter.Apply(bitmap);
            //SBIP.Helper.ImageConverter.SetColorPaletteToGray(bitmap);
            //bitmap.Save("ColorSpaceTest/LAB-Channel-B.png", ImageFormat.Png);
            //bitmap = new Bitmap("Bernd-Index52.jpg");
            //filter.ColorTriple = ColorTripleEnum.C;
            //bitmap = filter.Apply(bitmap);
            //SBIP.Helper.ImageConverter.SetColorPaletteToGray(bitmap);
            //bitmap.Save("ColorSpaceTest/LAB-Channel-C.png", ImageFormat.Png);

            ////LCH
            //Console.WriteLine("LCH");
            //filter.ColorSpace = ColorSpaceEnum.LCH;
            //bitmap = new Bitmap("Bernd-Index52.jpg");
            //filter.ColorTriple = ColorTripleEnum.A;
            //bitmap = filter.Apply(bitmap);
            //SBIP.Helper.ImageConverter.SetColorPaletteToGray(bitmap);
            //bitmap.Save("ColorSpaceTest/LCH-Channel-A.png", ImageFormat.Png);
            //bitmap = new Bitmap("Bernd-Index52.jpg");
            //filter.ColorTriple = ColorTripleEnum.B;
            //bitmap = filter.Apply(bitmap);
            //SBIP.Helper.ImageConverter.SetColorPaletteToGray(bitmap);
            //bitmap.Save("ColorSpaceTest/LCH-Channel-B.png", ImageFormat.Png);
            //bitmap = new Bitmap("Bernd-Index52.jpg");
            //filter.ColorTriple = ColorTripleEnum.C;
            //bitmap = filter.Apply(bitmap);
            //SBIP.Helper.ImageConverter.SetColorPaletteToGray(bitmap);
            //bitmap.Save("ColorSpaceTest/LCH-Channel-C.png", ImageFormat.Png);

            ////LUV
            //Console.WriteLine("LUV");
            //filter.ColorSpace = ColorSpaceEnum.LUV;
            //bitmap = new Bitmap("Bernd-Index52.jpg");
            //filter.ColorTriple = ColorTripleEnum.A;
            //bitmap = filter.Apply(bitmap);
            //SBIP.Helper.ImageConverter.SetColorPaletteToGray(bitmap);
            //bitmap.Save("ColorSpaceTest/LUV-Channel-A.png", ImageFormat.Png);
            //bitmap = new Bitmap("Bernd-Index52.jpg");
            //filter.ColorTriple = ColorTripleEnum.B;
            //bitmap = filter.Apply(bitmap);
            //SBIP.Helper.ImageConverter.SetColorPaletteToGray(bitmap);
            //bitmap.Save("ColorSpaceTest/LUV-Channel-B.png", ImageFormat.Png);
            //bitmap = new Bitmap("Bernd-Index52.jpg");
            //filter.ColorTriple = ColorTripleEnum.C;
            //bitmap = filter.Apply(bitmap);
            //SBIP.Helper.ImageConverter.SetColorPaletteToGray(bitmap);
            //bitmap.Save("ColorSpaceTest/LUV-Channel-C.png", ImageFormat.Png);

            ////RGB
            //Console.WriteLine("RGB");
            //filter.ColorSpace = ColorSpaceEnum.RGB;
            //bitmap = new Bitmap("Bernd-Index52.jpg");
            //filter.ColorTriple = ColorTripleEnum.A;
            //bitmap = filter.Apply(bitmap);
            //SBIP.Helper.ImageConverter.SetColorPaletteToGray(bitmap);
            //bitmap.Save("ColorSpaceTest/RGB-Channel-A.png", ImageFormat.Png);
            //bitmap = new Bitmap("Bernd-Index52.jpg");
            //filter.ColorTriple = ColorTripleEnum.B;
            //bitmap = filter.Apply(bitmap);
            //SBIP.Helper.ImageConverter.SetColorPaletteToGray(bitmap);
            //bitmap.Save("ColorSpaceTest/RGB-Channel-B.png", ImageFormat.Png);
            //bitmap = new Bitmap("Bernd-Index52.jpg");
            //filter.ColorTriple = ColorTripleEnum.C;
            //bitmap = filter.Apply(bitmap);
            //SBIP.Helper.ImageConverter.SetColorPaletteToGray(bitmap);
            //bitmap.Save("ColorSpaceTest/RGB-Channel-C.png", ImageFormat.Png);

            ////SRGB
            //Console.WriteLine("SRGB");
            //filter.ColorSpace = ColorSpaceEnum.SRGB;
            //bitmap = new Bitmap("Bernd-Index52.jpg");
            //filter.ColorTriple = ColorTripleEnum.A;
            //bitmap = filter.Apply(bitmap);
            //SBIP.Helper.ImageConverter.SetColorPaletteToGray(bitmap);
            //bitmap.Save("ColorSpaceTest/SRGB-Channel-A.png", ImageFormat.Png);
            //bitmap = new Bitmap("Bernd-Index52.jpg");
            //filter.ColorTriple = ColorTripleEnum.B;
            //bitmap = filter.Apply(bitmap);
            //SBIP.Helper.ImageConverter.SetColorPaletteToGray(bitmap);
            //bitmap.Save("ColorSpaceTest/SRGB-Channel-B.png", ImageFormat.Png);
            //bitmap = new Bitmap("Bernd-Index52.jpg");
            //filter.ColorTriple = ColorTripleEnum.C;
            //bitmap = filter.Apply(bitmap);
            //SBIP.Helper.ImageConverter.SetColorPaletteToGray(bitmap);
            //bitmap.Save("ColorSpaceTest/SRGB-Channel-C.png", ImageFormat.Png);

            ////XYZ
            //Console.WriteLine("XYZ");
            //filter.ColorSpace = ColorSpaceEnum.XYZ;
            //bitmap = new Bitmap("Bernd-Index52.jpg");
            //filter.ColorTriple = ColorTripleEnum.A;
            //bitmap = filter.Apply(bitmap);
            //SBIP.Helper.ImageConverter.SetColorPaletteToGray(bitmap);
            //bitmap.Save("ColorSpaceTest/XYZ-Channel-A.png", ImageFormat.Png);
            //bitmap = new Bitmap("Bernd-Index52.jpg");
            //filter.ColorTriple = ColorTripleEnum.B;
            //bitmap = filter.Apply(bitmap);
            //SBIP.Helper.ImageConverter.SetColorPaletteToGray(bitmap);
            //bitmap.Save("ColorSpaceTest/XYZ-Channel-B.png", ImageFormat.Png);
            //bitmap = new Bitmap("Bernd-Index52.jpg");
            //filter.ColorTriple = ColorTripleEnum.C;
            //bitmap = filter.Apply(bitmap);
            //SBIP.Helper.ImageConverter.SetColorPaletteToGray(bitmap);
            //bitmap.Save("ColorSpaceTest/XYZ-Channel-C.png", ImageFormat.Png);
            //#endregion GET BERND-INDEX52 COLOR TRIPLE IMAGES OF ALL COLOR SPACES

            Bitmap bitmap = new Bitmap("Cathedral.jpg");
            NSCannyEdgeMarker marker = new NSCannyEdgeMarker();
            // draw canny edge map into image
            bitmap = marker.Apply(bitmap);
            
            NSKeyPointAndColorBasedSegmentation filter = 
                new NSKeyPointAndColorBasedSegmentation();
            filter.Tolerance = Color.FromArgb(20, 20, 20);
            filter.KeyPoints = new List<PixelRGBA>(4);
            
            int x = 480;
            int y = 430;
            Color c = bitmap.GetPixel(x, y);
            PixelRGBA keypoint1 = new PixelRGBA
            {
                X = x,
                Y = y,
                R = c.R,
                G = c.G,
                B = c.B,
                Reserved = Color.FromArgb(255, 0, 0)
            };
            
            x = 300;
            y = 300;
            c = bitmap.GetPixel(x, y);
            PixelRGBA keypoint2 = new PixelRGBA
            {
                X = x,
                Y = y,
                R = c.R,
                G = c.G,
                B = c.B,
                Reserved = Color.FromArgb(255, 255, 0)
            };
            
            x = 170;
            y = 240;
            c = bitmap.GetPixel(x, y);
            PixelRGBA keypoint3 = new PixelRGBA
            {
                X = x,
                Y = y,
                R = c.R,
                G = c.G,
                B = c.B,
                Reserved = Color.FromArgb(255, 0, 255)
            };
            
            x = 350;
            y = 450;
            c = bitmap.GetPixel(x, y);
            PixelRGBA keypoint4 = new PixelRGBA
            {
                X = x,
                Y = y,
                R = c.R,
                G = c.G,
                B = c.B,
                Reserved = Color.FromArgb(0, 0, 255)
            };
            
            filter.KeyPoints.Add(keypoint1);
            filter.KeyPoints.Add(keypoint2);
            filter.KeyPoints.Add(keypoint3);
            filter.KeyPoints.Add(keypoint4);
            // apply NSKeyPointAndColorBasedSegmentation filter
            bitmap = filter.Apply(bitmap);
            bitmap.Save("NSKeyPointAndColorBasedSegmentation.png", ImageFormat.Png);
        }
    }
}
